package service;

import dao.SysCitysDao;
import entity.SysCitys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by chris on 17-5-15.
 */
@Service
public class SysCitysService {
    @Autowired
    private SysCitysDao sysCitysDao;

    @Transactional(readOnly = true)
    public List<SysCitys> list(){
        String hql = "from SysCitys";
        return sysCitysDao.findList(hql);
    }

    @Transactional(readOnly = true)
    public Map<Integer,String> transMap(){
        String hql = "from SysCitys";
        List<SysCitys> citys = sysCitysDao.findList(hql);
        Map<Integer,String> maps = new HashMap<Integer,String>();
        for (SysCitys city : citys){
            maps.put(city.getId(),city.getName());
        }
        return maps;
    }

    /*
    * 根据id找出实体
    * */
    @Transactional(readOnly = true)
    public SysCitys FindCityById(int id){
        return sysCitysDao.getById(id);
    }
}
